/* GUI CONVERTED from rcrp12.p (converter v1.76) Mon May 27 10:17:17 2002 */
/* rcrp12.p - Release Management Customer Schedules                          */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.11.2.8 $                                                     */
/*V8:ConvertMode=Report                                                      */
/* REVISION: 7.3      LAST MODIFIED: 10/16/92   BY: WUG *G462*               */
/* REVISION: 7.3      LAST MODIFIED: 05/07/93   BY: WUG *GA76*               */
/* REVISION: 7.3      LAST MODIFIED: 09/20/93   BY: WUG *GF68*               */
/* REVISION: 7.3      LAST MODIFIED: 09/30/93   BY: WUG *GG12*               */
/* REVISION: 7.4      LAST MODIFIED: 10/04/93   BY: WUG *H153*               */
/* REVISION: 7.4      LAST MODIFIED: 12/15/94   BY: rxm *GN16*               */
/* REVISION: 7.4      LAST MODIFIED: 11/16/94   BY: kjm *H0H1*               */
/* REVISION: 7.4      LAST MODIFIED: 02/13/96   BY: ais *H0JQ*               */
/* REVISION: 8.5      LAST MODIFIED: 07/15/95   BY: gwm *J049*               */
/* REVISION: 8.6      LAST MODIFIED: 08/09/96   BY: *K003* Vinay Nayak-Sujir */
/* REVISION: 8.6      LAST MODIFIED: 03/15/97   BY: *K04X* Steve Goeke       */
/* REVISION: 8.6      LAST MODIFIED: 04/02/97   BY: *K09H* Vinay Nayak-Sujir */
/* REVISION: 8.6      LAST MODIFIED: 06/27/97   BY: *K0FQ* Taek-Soo Chang    */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E     LAST MODIFIED: 05/29/98   BY: *J2MP* Niranjan R.       */
/* REVISION: 8.6E     LAST MODIFIED: 07/07/98   BY: *L03N* Niranjan R.       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 06/28/00   BY: *N0DM* Mudit Mehta       */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb               */
/* REVISION: 9.1      LAST MODIFIED: 08/18/00   BY: *N0MC* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 09/28/00   BY: *N0WD* Mudit Mehta       */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Old ECO marker removed, but no ECO header exists *GA73*                    */
/* $Revision: 1.11.2.8 $    BY: Katie Hilbert     DATE: 05/15/02  ECO: *P06H*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* BILL OF LADING PRINT */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "2+ "}
{cxcustom.i "RCRP12.P"}

define new shared variable addr as character format "x(38)" extent 6.
define shared variable global_recid as recid.
define variable disp_abs_id     as character.
define variable billto          as character format "x(38)" extent 6.
define variable shipto          as character format "x(38)" extent 6.
define variable company         as character format "x(38)" extent 6.
define variable print_date      as date.
define variable pages           as integer.
define variable cust            like so_cust.
define variable ship            like so_ship.
define variable addr_id         as character.
define variable abs_shipvia     like so_shipvia.
define variable abs_fob         like so_fob.
define variable abs_trans_mode  as character format "x(20)"
                                label "Mode of Transport".
define variable abs_carr_ref    as character format "x(20)"
                                label "Carrier Shipment Ref".
define variable abs_veh_ref     as character format "x(20)"
                                label "Vehicle ID".
define variable rpt_type        as character format "x(23)".
define variable type_nbr        as character format "x(17)".
define variable par_shipfrom    as character.
define variable par_id          as character.
define variable disp_item       as character format "x(24)"
                                label "Item Number".
define variable cum_qty         like sod_cum_qty[1] extent 0.
define variable abs_twt         like abs_gwt label "Tare Weight".
define variable abs_recid       as recid.
define variable soldto_id       as character.
define variable shipto_id       as character.
define variable i               as integer        no-undo.
define variable ship_date       as date           no-undo.
define variable shipper_id      like abs_id       no-undo.
define variable cmtindx_cdl     as character      no-undo.
define variable cmt_ctr         as integer        no-undo.
define variable l_nwt           like abs_nwt      no-undo.
define variable l_twt           like abs_twt      no-undo.
define variable l_gwt           like abs_gwt      no-undo.
define variable l_nwt1          like abs_nwt      no-undo.
define variable l_twt1          like abs_twt      no-undo.
define variable l_gwt1          like abs_gwt      no-undo.
define variable l_desc          like sod_desc     no-undo.
define variable l_wt_um         like pt_net_wt_um no-undo.
define variable l_um_conv       as decimal        no-undo.
define variable l_invitem       as logical        no-undo.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
abs_shipfrom         colon 28 label "Ship-From"
   si_desc              at 45 no-label
   abs_id               colon 28 label "Shipper"
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME


setFrameLabels(frame a:handle).           /* SET EXTERNAL LABELS */

FORM /*GUI*/ 
   abs_loc              colon 20 label "Ship-From Location"
   ad_name              at 45 no-label
   abs_shipto           colon 20 label "Ship-To/Dock"
   ad_line1             at 45 no-label
with STREAM-IO /*GUI*/  frame b side-labels width 80 attr-space.
setFrameLabels(frame b:handle).           /* SET EXTERNAL LABELS */

find abs_mstr where recid(abs_mstr) = global_recid no-lock no-error.

if available abs_mstr and abs_id begins "s" and abs_type = "s"
then do:
   find si_mstr where si_site = abs_shipfrom no-lock.

   display
      abs_shipfrom
      si_desc
      substring(abs_id,2,50) @ abs_id
   with frame a.
end.

repeat:
   do with frame a:
      prompt-for abs_shipfrom abs_id
      editing:
         global_site = input abs_shipfrom.

         if frame-field = "abs_shipfrom" then do:
            {mfnp05.i abs_mstr abs_id
               "abs_id begins ""s"" "
               abs_shipfrom
               "input abs_shipfrom"}
            if recno <> ? then do:
               find si_mstr where si_site = abs_shipfrom no-lock.

               disp_abs_id = substring(abs_id,2,50).

               display
                  abs_shipfrom
                  si_desc
                  disp_abs_id @ abs_id.
            end.
         end.
         else
            if frame-field = "abs_id" then do:
            {mfnp05.i abs_mstr abs_id
               "abs_shipfrom = input abs_shipfrom and abs_id begins ""s"" "
               abs_id
               " ""s"" + input abs_id"}
            if recno <> ? then do:
               find si_mstr where si_site = abs_shipfrom no-lock.

               disp_abs_id = substring(abs_id,2,50).

               display
                  abs_shipfrom
                  si_desc
                  disp_abs_id @ abs_id.
            end.
         end.
         else do:
            status input.
            readkey.
            apply lastkey.
         end.
      end.
   end.

   clear frame c all no-pause.

   find abs_mstr where abs_shipfrom = input abs_shipfrom
      and abs_id = "s" + input abs_id
      and abs_type = "s"
   no-lock no-error.
   if not available abs_mstr then do:
      {pxmsg.i &MSGNUM=8119 &ERRORLEVEL=3} /* SHIPPER DOES NOT EXIST */
      undo, retry.
   end.

   {&RCRP12-P-TAG1}
   if abs_inv_mov <> "" and
      not can-find
      (first im_mstr where
          im_inv_mov = abs_inv_mov and
          im_tr_type = "ISS-SO")
   then do:
      {&RCRP12-P-TAG2}
      {pxmsg.i &MSGNUM=5802 &ERRORLEVEL=3} /* NOT A SALES ORDER SHIPPER */
      undo, retry.
   end.  /* if abs_inv_mov */

   abs_recid = recid(abs_mstr).

   find si_mstr where si_site = abs_shipfrom no-lock.
   /* CHECK "BOL PRINTED" FLAG - ABS_STATUS(20) */

   if substring(abs_status,20,1) = "y" then do:
      {pxmsg.i &MSGNUM=8126 &ERRORLEVEL=2}
   end.

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "printer"
               &printWidth = 80
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "no"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.


   /* GET COMPANY ADDRESS */

   update company = "".

   find ad_mstr where ad_addr = abs_shipfrom no-lock no-error.
   if available ad_mstr then do:

      assign
         addr[1] = ad_name
         addr[2] = ad_line1
         addr[3] = ad_line2
         addr[4] = ad_line3
         addr[6] = ad_country.
      {mfcsz.i addr[5] ad_city ad_state ad_zip}.
      {gprun.i ""gpaddr.p"" }
      assign
         company[1] = addr[1]
         company[2] = addr[2]
         company[3] = addr[3]
         company[4] = addr[4]
         company[5] = addr[5]
         company[6] = addr[6].

   end.

   /* GET SOLDTO & SHIPTO ADDRESSES */

   update shipto = "".

   find ad_mstr where ad_addr = abs_shipto no-lock.

   assign
      shipto_id = ad_addr
      ship      = ad_addr
      addr[1]   = ad_name
      addr[2]   = ad_line1
      addr[3]   = ad_line2
      addr[4]   = ad_line3
      addr[6]   = ad_country.
   {mfcsz.i addr[5] ad_city ad_state ad_zip}.
   {gprun.i ""gpaddr.p"" }
   assign
      shipto[1] = addr[1]
      shipto[2] = addr[2]
      shipto[3] = addr[3]
      shipto[4] = addr[4]
      shipto[5] = addr[5]
      shipto[6] = addr[6].

   update billto = "".

   find ad_mstr where ad_addr = abs_shipto no-lock.

   assign
      soldto_id = ad_addr
      cust = ad_addr.
   find ls_mstr where ls_addr = ad_addr and ls_type = "customer"
   no-lock no-error.

   if not available ls_mstr and ad_ref > "" then do:
      find ls_mstr where ls_addr = ad_ref and ls_type = "customer"
      no-lock no-error.

      if available ls_mstr then
         assign
            soldto_id = ad_ref
            cust = ad_ref.
      else do:
         addr_id = ad_ref.
         find ad_mstr where ad_addr = addr_id no-lock.
         if ad_ref > "" then do:
            find ls_mstr where ls_addr = ad_ref
               and ls_type = "customer" no-lock no-error.
            if available ls_mstr then
               assign
                  soldto_id = ad_ref
                  cust = ad_ref.
         end.
      end.
   end.

   find ad_mstr where ad_addr = soldto_id no-lock.

   assign
      addr[1] = ad_name
      addr[2] = ad_line1
      addr[3] = ad_line2
      addr[4] = ad_line3
      addr[6] = ad_country.
   {mfcsz.i addr[5] ad_city ad_state ad_zip}.
   {gprun.i ""gpaddr.p"" }
   assign
      billto[1]      = addr[1]
      billto[2]      = addr[2]
      billto[3]      = addr[3]
      billto[4]      = addr[4]
      billto[5]      = addr[5]
      billto[6]      = addr[6]
      shipper_id     = substring(abs_id,2,20)
      ship_date      = abs_shp_date
      print_date     = today
      abs_shipvia    = substring(abs__qad01,1,20)
      abs_fob        = substring(abs__qad01,21,20)
      abs_carr_ref   = substring(abs__qad01,41,20)
      abs_trans_mode = substring(abs__qad01,61,20)
      abs_veh_ref    = substring(abs__qad01,81,20).

   /* PRINT HEADING */

   FORM /*GUI*/  header
      skip (3)
      company[1]                                   at 4
      getTermLabel("B_I_L_L__O_F__L_A_D_I_N_G",35) to 79 format "x(35)"
      company[2]                                   at 4
      company[3]                                   at 4
      type_nbr                                     to 58
      shipper_id
      company[4]                                   at 4
      getTermLabelRtColon("SHIP_DATE",14)          to 58 format "x(14)"
      ship_date
      company[5]                                   at 4
      getTermLabelRtColon("PRINT_DATE",14)         to 58 format "x(14)"
      print_date
      getTermLabelRtColon("PAGE_OF_REPORT",15)     to 58 format "x(15)"
      string(page-number)
      company[6]                                   at 4
      skip (1)
      getTermLabel("SOLD_TO",7) + ":"              at 8
      cust
      getTermLabel("SHIP_TO",7) + ":"              at 46
      ship
      skip (1)
      billto[1]                                    at 8
      shipto[1]                                    at 46
      billto[2]                                    at 8
      shipto[2]                                    at 46
      billto[3]                                    at 8
      shipto[3]                                    at 46
      billto[4]                                    at 8
      shipto[4]                                    at 46
      billto[5]                                    at 8
      shipto[5]                                    at 46
      billto[6]                                    at 8
      shipto[6]                                    at 46
      skip (2)
      skip(3)
      getTermLabelRtColon("SHIP_VIA",12)           to 12 format "x(12)"
      abs_shipvia
      getTermLabelRtColon("MODE_OF_TRANSPORT",24)  to 58 format "x(24)"
      abs_trans_mode
      getTermLabelRtColon("FOB_POINT",12)          to 12 format "x(12)"
      abs_fob
      getTermLabelRtColon("CARRIER_SHIPMENT_REFERENCE",24) to 58
      format "x(24)"
      abs_carr_ref
      getTermLabelRtColon("VEHICLE_ID",15)         to 58 format "x(15)"
      abs_veh_ref
      skip(3)
   with STREAM-IO /*GUI*/  frame heading page-top width 90 no-box no-attr-space no-labels.

   if abs_id begins "s"
   then type_nbr = getTermLabelRtColon("SHIPPER_ID",17).
   else type_nbr = getTermLabelRtColon("CONTAINER_ID",17).
   view frame heading.

   /* PRINT COMMENTS IF ANY */

   if abs_cmtindx > 0 then do:
      {gpcmtprt.i &type=BL &id=abs_cmtindx &pos=3}
      put skip(1).
   end.

   /* PRINT BOL DETAIL */

   assign
      par_shipfrom = abs_shipfrom
      par_id = abs_id
      l_nwt   = 0.0
      l_twt   = 0.0
      l_gwt   = 0.0
      l_nwt1  = 0.0
      l_twt1  = 0.0
      l_gwt1  = 0.0
      l_invitem = no.

   do with frame d down with no-box:

      /* DEFINING FORM TO PRINT BILL OF LADING DETAILS */
      FORM /*GUI*/ 
         pt_desc1
         abs_qty  column-label "Qty"
         abs_nwt  column-label "Net!Weight"
         abs_twt  column-label "Tare!Weight"
         abs_gwt  column-label "Gross!Weight"
         pt_net_wt_um
      with STREAM-IO /*GUI*/  frame d no-attr-space no-box width 80.

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame d:handle).

      for each abs_mstr no-lock
         where abs_shipfrom = par_shipfrom
           and abs_par_id = par_id,
         each pt_mstr no-lock
            where pt_part = abs_item
            break by pt_part with frame d:

         assign
            cmtindx_cdl = cmtindx_cdl + "," + string(abs_cmtindx)
            l_invitem   = yes
            abs_twt     = abs_gwt - abs_nwt.
         accumulate abs_qty (total by pt_part).
         accumulate abs_nwt (total by pt_part).
         accumulate abs_twt (total by pt_part).
         accumulate abs_gwt (total by pt_part).

         if last-of(pt_part) then do:
            display
               pt_desc1
               (accum total by pt_part abs_qty)
               @ abs_qty column-label "Qty" format "->>>>>>9.9"
               (accum total by pt_part abs_nwt)
               @ abs_nwt column-label "Net!Weight" format "->>>>>>9.9"
               (accum total by pt_part abs_twt)
               @ abs_twt column-label "Tare!Weight" format "->>>>>>9.9"
               (accum total by pt_part abs_gwt)
               @ abs_gwt column-label "Gross!Weight" format "->>>>>>9.9"
               pt_net_wt_um
            with width 80 STREAM-IO /*GUI*/ .
            down 1.
            do cmt_ctr = 1 to num-entries(cmtindx_cdl):
               if integer(entry(cmt_ctr,cmtindx_cdl)) > 0 then do:
                  {gpcmtprt.i &type=BL
                     &id=integer(entry(cmt_ctr,cmtindx_cdl)) &pos=3}
                  put skip(1).
               end.
            end.

            cmtindx_cdl = "".
         end. /*IF LAST-OF(PT_PART) THEN DO */

         if last(pt_part) then do:

            assign
               l_wt_um = pt_net_wt_um
               l_nwt   = accum total abs_nwt
               l_twt   = accum total abs_twt
               l_gwt   = accum total abs_gwt.
         end. /* IF LAST-OF(PT_PART) THEN DO */

         
/*GUI*/ {mfguichk.i  &warn=false} /*Replace mfrpchk*/

      end. /*END FOR ABS_MSTR */

      /* FOR EACH LOOP FOR PRINTING BILL OF LADING FOR MEMO ITEM */

      for each abs_mstr
         fields(abs_cmtindx abs_gwt abs_id abs_inv_mov abs_item
                abs_line abs_loc abs_nwt abs_order abs_par_id abs_qty
                abs_shipfrom abs_shipto abs_shp_date abs_status
                abs_trl_cmtindx abs_type abs_wt_um abs__qad01) no-lock
         where abs_shipfrom = par_shipfrom
           and abs_par_id = par_id
           and abs_id begins "i"
           and not can-find ( first pt_mstr where pt_part = abs_item )
         break by abs_item with frame d:

         for first sod_det fields( sod_desc sod_line sod_nbr sod_part)
            where sod_nbr = abs_order
            and   sod_line = integer(abs_line)
            and   sod_part = abs_item no-lock:
         end. /* FOR SOD_DET AVAILABLE */
         if available sod_det then
            l_desc = sod_desc.
         else do:
            for first idh_hist
               fields( idh_desc idh_line idh_nbr idh_part)
               where idh_nbr  = abs_order
               and   idh_line = integer(abs_line)
               and   idh_part = abs_item no-lock:
               l_desc = idh_desc.
            end. /*FOR IDH_HIST */
         end. /* ELSE DO  */
         assign
            l_um_conv  = 1
            abs_twt    = abs_gwt - abs_nwt.
         {gprun.i ""gpumcnv.p""
            "(input abs_wt_um,
              input l_wt_um,
              input abs_item,
              output l_um_conv )"}
         if l_um_conv  = ? then l_um_conv  = 1.
         accumulate abs_qty (total by abs_item).
         accumulate abs_nwt (total by abs_item).
         accumulate abs_twt (total by abs_item).
         accumulate abs_gwt (total by abs_item).
         if last-of(abs_item) then do:
            display
               l_desc @ pt_desc1 format "x(22)"
               (accum total by abs_item abs_qty)
               @ abs_qty format "->>>>>>9.9"
               (accum total by abs_item abs_nwt) * l_um_conv
               @ abs_nwt format "->>>>>>9.9"
               (accum total by abs_item abs_twt) * l_um_conv
               @ abs_twt format "->>>>>>9.9"
               (accum total by abs_item abs_gwt) * l_um_conv
               @ abs_gwt format "->>>>>>9.9"
               abs_wt_um @ pt_net_wt_um
            with width 80 STREAM-IO /*GUI*/ .
            down 1.
            assign
               l_nwt1 = (accum total by abs_item abs_nwt)
                      * l_um_conv + l_nwt1
               l_twt1 = (accum total by abs_item abs_twt)
                      * l_um_conv + l_twt1
               l_gwt1 = (accum total by abs_item abs_gwt)
                      * l_um_conv + l_gwt1.
         end. /*IF LAST-OF(ABS_ITEM) THEN DO */

         if last(abs_item) then
            assign
               l_nwt   =  l_nwt + l_nwt1
               l_twt   =  l_twt + l_twt1
               l_gwt   =  l_gwt + l_gwt1
               l_wt_um = abs_wt_um when (l_invitem = no).

         
/*GUI*/ {mfguichk.i  &warn=false} /*Replace mfrpchk*/

      end.  /*FOR EACH OF MEMO ITEMS */

      underline abs_nwt abs_twt abs_gwt.
      down 1.
      display
         l_nwt @ abs_nwt format "->>>>>>9.9"
         l_twt @ abs_twt format "->>>>>>9.9"
         l_gwt @ abs_gwt format "->>>>>>9.9"
         l_wt_um @ pt_net_wt_um
      with width 80 STREAM-IO /*GUI*/ .
   end. /* DO LOOP WITH FRAME D */

   /* PRINT TRAILER COMMENTS IF ANY */

   find abs_mstr where recid(abs_mstr) = abs_recid no-lock.
   if abs_trl_cmtindx > 0 then do:
      {gpcmtprt.i &type=BL &id=abs_trl_cmtindx &pos=3}
      put skip(1).
   end.

   {mfreset.i}
/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/


   do transaction:
      /* MARK PRINTED */
      /* WE NOW USE ABS_STATUS(20) FOR THE "BOL PRINTED" FLAG */
      find abs_mstr where recid(abs_mstr) = abs_recid exclusive-lock.

      substring(abs_status,20,1) = "y".

      assign
         global_recid = recid(abs_mstr).

      release abs_mstr.
   end.
end.
